package com.winsomely.leecode;

/**
 * 找出字符串中最长的回文子串
 * 
 * @author liujiawei
 *
 */
public class LongestPalindrome {

	private boolean isPalindrome(String cs) {
		System.out.println(cs);
		int b = 0;
		int e = cs.length() - 1;
		while (b < e) {
			if (cs.charAt(b++) != cs.charAt(e--)) {
				return false;
			}
		}
		return true;
	}

	public String longestPalindrome(String s) {
		int l = s.length();
		while (l > 0) {
			int b = 0;
			do {
				String cs = s.substring(b, b + l);
				if (this.isPalindrome(cs)) {
					return cs;
				}
				b++;
			} while (b + l <= s.length());
			l--;
		}
		return "";
	}

	public static void main(String[] args) {
		LongestPalindrome t = new LongestPalindrome();
		String cs = "hgfjytfjughfjhgfjdhtjhfkjyhghgfdggfjdhgfdjhgfjhfcvcfhdhgh";
		System.out.println(t.longestPalindrome(cs));
	}

}
